package com.dennisstepp.database;

import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

public class DepressionGlassDbAdapter {
	// Database fields
	public static final String KEY_ROWID = " _id";
	public static final String KEY_PATTERN = "Pattern";
	public static final String KEY_COLOR = "Color";
	public static final String KEY_PIECE = "Piece";
	public static final String KEY_VALUE = "Value";
	public static final String KEY_QUANTITY = "Quantity";
	public static final String KEY_CONDITION = "Condition";
	public static final String DATABASE_TABLE = "DepressionGlass";
	// identifing field
	// identifing patterns
	private static final String americanSweetheart = "\"American Sweetheart\"";
	private static final String holiday = "\"Holiday\"";
	private static final String madrid = "\"Madrid\"";
	private static final String vitrock = "\"Vitrock\"";
	// identifing colors
	private static final String monax = "\"Monax\"";
	private static final String pink = "\"Pink\"";
	private static final String miscolor = "\"Miscolor\"";
	private static final String amber = "\"Amber\"";

	private Context context;
	private SQLiteDatabase database;
	private DatabaseHelper dbHelper;
	
	

	public DepressionGlassDbAdapter(Context context) {
		this.context = context;
	}

	public DepressionGlassDbAdapter open() throws SQLException {
		dbHelper = new DatabaseHelper(context);
		database = dbHelper.getWritableDatabase();
		return this;
	}

	public void close() {
		dbHelper.close();
	}

	public Cursor fetchAllAmericanSweetheartMonax() {
		return database.query(DATABASE_TABLE,
				new String[] { KEY_ROWID, KEY_PATTERN, KEY_PIECE, KEY_VALUE,
						KEY_QUANTITY, KEY_CONDITION }, KEY_PATTERN + "="
						+ americanSweetheart + " and " + KEY_COLOR + "="
						+ monax, null, null, null, null);
	}

	public Cursor fetchAllAmericanSweetheartPink() {
		return database.query(DATABASE_TABLE,
				new String[] { KEY_ROWID, KEY_PATTERN, KEY_PIECE, KEY_VALUE,
						KEY_QUANTITY, KEY_CONDITION },
				KEY_PATTERN + "=" + americanSweetheart + " and " + KEY_COLOR
						+ "=" + pink, null, null, null, null);
	}

	public Cursor fetchAllHolidayPink() {
		return database.query(DATABASE_TABLE,
				new String[] { KEY_ROWID, KEY_PATTERN, KEY_PIECE, KEY_VALUE,
						KEY_QUANTITY, KEY_CONDITION }, KEY_PATTERN + "="
						+ holiday + " and " + KEY_COLOR + "=" + pink, null,
				null, null, null);
	}

	public Cursor fetchAllHolidayMiscolor() {
		return database.query(DATABASE_TABLE,
				new String[] { KEY_ROWID, KEY_PATTERN, KEY_PIECE, KEY_VALUE,
						KEY_QUANTITY, KEY_CONDITION }, KEY_PATTERN + "="
						+ holiday + " and " + KEY_COLOR + "=" + miscolor, null,
				null, null, null);
	}

	public Cursor fetchAllMadridAmber() {
		return database.query(DATABASE_TABLE,
				new String[] { KEY_ROWID, KEY_PATTERN, KEY_PIECE, KEY_VALUE,
						KEY_QUANTITY, KEY_CONDITION }, KEY_PATTERN + "="
						+ madrid + " and " + KEY_COLOR + "=" + amber, null,
				null, null, null);
	}

	public Cursor fetchAllVitrock() {
		return database.query(DATABASE_TABLE,
				new String[] { KEY_ROWID, KEY_PATTERN, KEY_PIECE, KEY_VALUE,
						KEY_QUANTITY, KEY_CONDITION }, KEY_PATTERN + "="
						+ vitrock, null, null, null, null);
	}


}
